package com.droolsBoot.model;

import com.droolsBoot.service.NewKieBase;
import org.kie.api.KieBase;
import org.kie.api.runtime.StatelessKieSession;

import java.util.List;


/**
 *  自定义的Kie聚合类
 *  该类主要属性包括了
 *  KieBase
 *  StatelessKieSession
 *  其目的是更更方便的操作规则库，将这些值放到内存静态变量中
 *  使用时只需要对该类进行一个遍历引用就可以实现规则的调用
 *  大大减少了创建规则相关对象的内存开销。
 */
public class PromoteExecute {
    //促销编号：
    private String promoteCode;
    //业务Kbase
    private KieBase workKbase;
    //业务session
    private StatelessKieSession workSession;
    //规则内容
    private String workContent;
    //促销规则名称：
    private List<String> ruleName;

    private String promoteName;

    public String getPromoteName() {
        return promoteName;
    }

    public void setPromoteName(String promoteName) {
        this.promoteName = promoteName;
    }

    public String getWorkContent() {
        return workContent;
    }

    public void setWorkContent(String workContent) {
        this.workContent = workContent;
    }

    public List<String> getRuleName() {
        return ruleName;
    }

    public void setRuleName(List<String> ruleName) {
        this.ruleName = ruleName;
    }


    public String getPromoteCode() {
        return promoteCode;
    }

    public void setPromoteCode(String promoteCode) {
        this.promoteCode = promoteCode;
    }

    public KieBase getWorkKbase() {
        if (this.workKbase == null) {
            this.setWorkKbase();
        }
        return workKbase;
    }

    public void setWorkKbase() {
        //获取规则,使用 KieHelper 创建 KieBase
        this.workKbase = NewKieBase.rulekieBase(this.getWorkContent());
    }

    public StatelessKieSession getWorkSession() {
        if (this.workSession == null) {
            this.setWorkSession();
        }
        return workSession;
    }

    public void setWorkSession() {
        if (null != this.getWorkKbase()) {
            //创建 kieSession
            // 注意： 这里创建的是无状态的session
            this.workSession = this.getWorkKbase().newStatelessKieSession();
        }
    }
}
